<%--
  Created by IntelliJ IDEA.
  User: 仲春初九
  Date: 2019/11/23
  Time: 10:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>


    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/admin/css/admin.css" />

    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<form id="updateComm">
    <input type="hidden" value="${comm.cid}" name="cid">
    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="cname" lay-verify="title"  value="${comm.cname}" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品价格</label>
        <div class="layui-input-block">
            <input type="text" name="cprice" lay-verify="title" value="${comm.cprice}" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">供应商</label>
        <div class="layui-input-block">
            <input type="text" name="cprovider" lay-verify="title" value="${comm.cprovider}" autocomplete="off" placeholder="请输入供应商" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="margin-left: 30px; padding-left: 10px;">
        <div class="layui-input-block">
            <button id="sub" class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script>
    layui.use(['form'], function() {
        var form = layui.form();
        form.render();
        form.on('submit(formDemo)', function(data) {
            $.post("${pageContext.request.contextPath}/CommServlet.action?flag=updateById",$("#updateComm").serialize(),
                function (result) {

                    var result=eval('('+result+')');
                    if(result.error){
                        alert(result.error);
                    }else{
                        layer.msg('修改成功！', {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            form.render();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                },
                "text"
            );
            return false;
        });
        form.render();
    });
</script>
</html>
